package com.lbkj.ops.controller;

import com.lbkj.ops.common.exception.Http400Exception;
import com.lbkj.ops.common.exception.Http401Exception;
import com.lbkj.ops.common.util.SessionUtils;
import com.lbkj.ops.dao.OpsUserDao;
import com.lbkj.ops.model.OpsUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jian.liu
 * @date 2020/10/28
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private OpsUserDao opsUserDao;

    @PostMapping
    public void login(@RequestBody OpsUser loginUser) {
        OpsUser user = opsUserDao.findByAccountAndPwd(loginUser.getAccount(), loginUser.getPwd());
        if(user == null) {
            throw new Http400Exception("用户名或密码错误");
        }
        SessionUtils.putLoginUser(user);
    }


}
